package com.example.admin.yuejian21.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.example.admin.yuejian21.Adapter.PicAdapter;
import com.example.admin.yuejian21.Adapter.shaituListAdapter;
import com.example.admin.yuejian21.Bean.Pic;
import com.example.admin.yuejian21.Bean.shaitu;
import com.example.admin.yuejian21.R;
import com.example.admin.yuejian21.Service.Service;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.admin.yuejian21.activity.LoginActivity.userid;

public class ShowlistActivity extends AppCompatActivity {
    private RecyclerView recyclerView;

    private shaituListAdapter adapter;
    private List<shaitu> Piclist;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_showlist);
        recyclerView =
                (RecyclerView) findViewById(R.id.recyclerView);
        Retrofit retrofit=new Retrofit.Builder().baseUrl("http://172.24.10.175/workout/api.php/").addConverterFactory(GsonConverterFactory.create())
                .build();
        Service service=retrofit.create(Service.class);
        Call<List<shaitu>> call=service.shaituList(userid);
        call.enqueue(new Callback<List<shaitu>>() {
            @Override
            public void onResponse(Call<List<shaitu>> call, Response<List<shaitu>> response) {

                    Piclist = response.body();
                    adapter = new shaituListAdapter (ShowlistActivity.this, Piclist);
                    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(ShowlistActivity.this);
                    linearLayoutManager.setOrientation(linearLayoutManager.VERTICAL);
                    recyclerView.setLayoutManager(linearLayoutManager);
                    recyclerView.setAdapter(adapter);
                    recyclerView.setItemAnimator(new DefaultItemAnimator());
                }



            @Override
            public void onFailure(Call<List<shaitu>> call, Throwable t) {

            }
        });



    }
}
